#include "ns.h"

extern union Nsipc nsipcbuf;

void
output(envid_t ns_envid)
{
    int r=0;
    envid_t from=0;
	binaryname = "ns_output";

	// LAB 6: Your code here:
	// 	- read a packet from the network server
	//	- send the packet to the device driver
    while(1) {
        if((r=ipc_recv(&from, &nsipcbuf.pkt, NULL))==NSREQ_OUTPUT) {
            //cprintf("\nBuffer: %s Len: %d From: %x nsid: %x", &nsipcbuf.pkt.jp_data, nsipcbuf.pkt.jp_len, from, ns_envid);
            //cprintf("\nSending to driver");
            r   = sys_ns_send(&nsipcbuf.pkt.jp_data, nsipcbuf.pkt.jp_len);
        } else {
            cprintf("output: error %x\n", r);
            sys_yield();
        }
    }
}
